package org.grow.took.Controller;

import org.grow.took.entity.EnumDto;
import org.grow.took.entity.enums.DealState;
import org.grow.took.entity.enums.ProfessionType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;


@RestController
@RequestMapping("/ceto/common/")
public class CommonController {
     @GetMapping("/professionTypes")
    public List<EnumDto> getprofessionTypes(){
           ProfessionType[] values = ProfessionType.values();
//         return Arrays.stream(values)
//                 .map(p-> {
//                     EnumDto enumDto = new EnumDto();
//                     enumDto.setIndex(p.ordinal());
//                     enumDto.setValue(p.name());
//                     enumDto.setText(p.getText());
//                     return enumDto;
//                 }).collect(Collectors.toList());
         Stream<ProfessionType> stream = Arrays.stream(values);
         //map函数一个入参，一个返回值，入参类型随意，返回值类型随意
         Stream<EnumDto> enumDtoStream = stream.map(x -> {
             EnumDto enumDto = new EnumDto();
             enumDto.setIndex(x.ordinal());
             enumDto.setValue(x.name());
             enumDto.setText(x.getText());
             return enumDto;

         });
         return enumDtoStream.collect(Collectors.toList());


     }

     @RequestMapping("/dealState")
    public  List<EnumDto> getDealSates(){
                  return Arrays.stream(DealState.values())
                 .map(p-> {
                     EnumDto enumDto = new EnumDto();
                     enumDto.setIndex(p.ordinal());
                     enumDto.setValue(p.name());
                     enumDto.setText(p.getText());
                     return enumDto;
                 }).collect(Collectors.toList());


     }


}
